package api

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"seat-service/initialization"
	"seat-service/model"
	"seat-service/model/dto"
	"seat-service/response"
	service "seat-service/service/impl"
)

type StudentAdminApi struct {
}

var studentAdminService service.StudentAdminService

// GetAllStudentInformations 得到所有学生的信息
func (s *StudentAdminApi) GetAllStudentInformations(context *gin.Context) {
	//接收请求参数
	var queryStudentCondition dto.GetAssignStudent
	if err := context.ShouldBindJSON(&queryStudentCondition); err != nil {
		resp.Fail(context, response.CodeParamError, nil)
		return
	}
	total, assignStudents, err := studentAdminService.SelectAllStudents(queryStudentCondition)
	if err != nil {
		initialization.SeatLogger.Error("studentAdminService.SelectAllStudents(queryStudentCondition) is failed", zap.Error(err))
		resp.Fail(context, response.CodeServerBusy, nil)
		return
	}
	respData := struct {
		Students []model.Student `json:"students"`
		Total    int64           `json:"total"`
	}{
		Students: assignStudents,
		Total:    total,
	}
	resp.Success(context, response.CodeSuccess, respData)
}

// ChangeStudentStatus 取消学生的违规状态
func (s *StudentAdminApi) ChangeStudentStatus(context *gin.Context) {
	//接收请求参数
	var studentIds dto.CancelByIds
	err := context.ShouldBindJSON(&studentIds)
	if err != nil {
		resp.Fail(context, response.CodeParamError, nil)
		return
	}
	//接收更改后的信息
	students, err := studentAdminService.CancelViolationStudentsByIds(studentIds)
	if err != nil {
		initialization.SeatLogger.Error("studentAdminService.CancelViolationStudentsByIds(studentIds) is failed", zap.Error(err))
		resp.Fail(context, response.CodeServerBusy, nil)
		return
	}
	resp.Success(context, response.CodeSuccess, students)
}
